var Tool = {
    log : function(logObj) {
        if(Config.channelID == 2 && typeof BK != "undefined"){
            BK.Script.log(1,1,logObj);
        }if(Config.channelID == 101){
            // console.log(logObj);
        }else{
            // console.log(logObj);
        }
    },
    // log : console.log,
    objectPrint : function(obj) {
        console.log(JSON.stringify(obj));
    },
    destroyDom : function(dom){
        if(!dom) return;
        Laya.timer.frameOnce(2, this, function (dom) { 
            if(!dom._destroyed){
                dom.destroy(); 
            }
        },[dom]);
    },
    randomRange : function(Min,Max){
        var Range = Max - Min;
        var Rand = Math.random();
        return(Min + Math.round(Rand * Range));
    },
    randomSort : function(a, b) { //随机排序
        return Math.random() > 0.5 ? -1 : 1;
    },
    numberToIndeies : function(n) {
        var ret = [];
        while(n >= 10){
            ret.push(n%10);
            n = Math.floor(n/10);
        }
        ret.push(n);
        ret.reverse();
        return ret;
    },
    getMondayTime : function(){//星期一早上8点
        var now = new Date(); 
        var nowTime = now.getTime() ; 
        var day = now.getDay();
        var oneDayLong = 24*60*60*1000; 
        var MondayTimeNow = nowTime - (day-1)*oneDayLong;
        var extraTime = MondayTimeNow%oneDayLong;
        var monday = new Date(MondayTimeNow - extraTime);
        var mondayTime = monday.getTime()/1000;
        return mondayTime;
    },
    getTodayTime : function(){ //今天0点时间戳
        var timeStamp = new Date(new Date().setHours(0, 0, 0, 0)) / 1000;
        var ToDayAgo = timeStamp;
        return ToDayAgo;
    },
    flipPositionY : function(pos) {
        return {
            x : pos.x,
            y : (Config.GameHeight-pos.y),
        };
    },
    isObjectEqual : function( x, y ) {
        // If both x and y are null or undefined and exactly the same
        if ( x === y ) {
            return true;
        }

        // If they are not strictly equal, they both need to be Objects
        if ( ! ( x instanceof Object ) || ! ( y instanceof Object ) ) {
            return false;
        }

        //They must have the exact same prototype chain,the closest we can do is
        //test the constructor.
        if ( x.constructor !== y.constructor ) {
            return false;
        }

        for ( var p in x ) {
            //Inherited properties were tested using x.constructor === y.constructor
            if ( x.hasOwnProperty( p ) ) {
                // Allows comparing x[ p ] and y[ p ] when set to undefined
                if ( ! y.hasOwnProperty( p ) ) {
                    return false;
                }

                // If they have the same strict value or identity then they are equal
                if ( x[ p ] === y[ p ] ) {
                    continue;
                }

                // Numbers, Strings, Functions, Booleans must be strictly equal
                if ( typeof( x[ p ] ) !== "object" ) {
                    return false;
                }

                // Objects and Arrays must be tested recursively
                if ( ! Object.equals( x[ p ], y[ p ] ) ) {
                    return false;
                }
            }
        }

        for ( p in y ) {
            // allows x[ p ] to be set to undefined
            if ( y.hasOwnProperty( p ) && ! x.hasOwnProperty( p ) ) {
                return false;
            }
        }
        return true;
    },
    returnCountDownStr : function(countDownTime){
        var countDownStr = "";
        if(countDownTime <= 0) return "00:00";
        var minuteTime = parseInt(countDownTime/60);
        var secondTime = parseInt(countDownTime % 60);
        if(minuteTime < 10) countDownStr += "0";
        countDownStr += minuteTime +":";
        if(secondTime < 10) countDownStr += "0";
        countDownStr += secondTime +"";
        return countDownStr;
    },
    NumAscSort: function(a,b){
        return a - b;
    },
    NumDescSort : function(a,b){
        return b - a;
    },
    insertSpace : function (str) {
        if(typeof str != "string")  str = str.toString();
        return str.split("").join(" ");
    }
};
